<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./ejs.js"></script>
  </head>
  <body>
    <div class="container"></div>
    <p></p>
    <script>
      let arr = [
        {
          name: "张三",
          age: 20,
        },
        {
          name: "王五",
          age: 21,
        },
      ];
      // let myname = "哈哈";
      // let res = ejs.render("<p>我的名字是:<%=myname%></p>", { myname: myname });
      // console.log(res);
      // document.querySelector(".container").innerHTML = res;
 
      let res=ejs.render(
      `  <ul>
         <% arr.forEach(item=>{ %>
            <li>姓名是：<%=item.name%>
                年龄是：<%=item.age%>
              </li>
        <%  })  %>
          </ul>`,{arr}
      )
      document.querySelector(".container").innerHTML = res;

    </script>
  </body>
</html>
